/*  ___ _  ____  __ _  _    ___       _ _          
 * | _ \ |/ /  \/  | \| |  / _ \ _ _ | (_)_ _  ___ 
 * |  _/ ' <| |\/| | .` | | (_) | ' \| | | ' \/ -_)
 * |_| |_|\_\_|  |_|_|\_|  \___/|_||_|_|_|_||_\___|
 */
#ifndef __PKMNONLINE_ACTOR_H__
#define __PKMNONLINE_ACTOR_H__
#include "entity.h"
#include "map.h"
#include "animation.h"

enum {
	DIR_UP,
	DIR_RIGHT,
	DIR_DOWN,
	DIR_LEFT,
	DIR_NONE
};

#include <string.h>

//
// Represents a animated moveable object.
//
class CActor: public CEntity {
public:
	CActor(int nX, int nY);

	void	Think(int tick);
	bool	CanMove(int nDir);
	void	Move(int nDir);
	void	SetSpeed(float flSpeed)	{ m_flSpeed = flSpeed; }
	void	SetMap(CMap *pMap)		{ m_pMap = pMap; }
	float	GetSpeed() const		{ return m_flSpeed; }
	CMap   *GetMap() const			{ return m_pMap; }
	int		GetOffsetX() const		{ return m_nOffsetX; }
	int		GetOffsetY() const		{ return m_nOffsetY; }
	bool	IsMoving() const		{ return m_bMoving; }

	const char *GetName() const { return m_szName; }

	void SetName(const char *szName) 
	{
		strcpy(m_szName, szName);
	}

	void SetAnimation(CAnimation *ani) 
	{ 
		m_pAni = ani; 
		if (ani)
		{
			switch (m_nDirection) 
			{
				case DIR_UP: ani->SetAnimation(3); break;
				case DIR_RIGHT: ani->SetAnimation(2); break;
				case DIR_DOWN: ani->SetAnimation(1); break;
				case DIR_LEFT: ani->SetAnimation(0); break;
			}
			ani->SetFrame(1);
			ani->Stop();
		}
	}

	CAnimation *GetAnimation() const { return m_pAni; }

private:
	void	HandleMovement(int tick);
	void	StopMovement();

	float	m_flSpeed;
	float	m_flMoveDistance;
	int		m_nDirection;
	int		m_nOffsetX;
	int		m_nOffsetY;
	int		m_nPrevUpdate;
	bool	m_bMoving;
	CMap   *m_pMap;

	bool    m_bNameVisible;
	char    m_szName[128];

	// TODO: Implement this. When set to true a moving actor should keep moving int
	//       the direction that it is facing until it reaches a blocked tile or the
	//       edge of the level.
	bool    m_bRepeatMovement; 

	CAnimation *m_pAni;
};

#endif /* __PKMNONLINE_ACTOR_H__ */
